<?php
namespace My\Controller;
use Utuo\BackgroundController;
class MicroVoteCensusController extends BackgroundController
{   private $micro_vote_id;
	public function _initialize() {
		$this->micro_vote_id=I('micro_vote_id',0,'intval');
		$this->setControllerTitle('投票结果统计');
		$this->setActionTitle(array(
				'index' => '统计信息',
				
		),null,array('micro_vote_id'=>$this->micro_vote_id));
		$this->setActionNav('index');
	}
	

	public function indexAction() {
		$condation=array(
				'm.status'=>1,
				'm.is_deleted'=>0,
				'r.status'=>1,
				'r.is_deleted'=>0,
				'm.cid'=>$this->aid,
				'r.micro_vote_id '=>$this->micro_vote_id,
				'm.micro_vote_id '=>$this->micro_vote_id
		);
		$m=M('MicroVoteItem m');
		$microVoteCensus=$m->join("__MICRO_VOTE_RECORD__ r on m.id=r.selected","left")->where($condation)->field('m.id,count(m.id) as num,m.title')->group('m.id,m.title')->order('num desc')->select();
		$i=1;
		foreach ($microVoteCensus as $key=>&$v)
		{
			if($key==0)
			{
				$v['sort']=1;
			}elseif($microVoteCensus[$key]['num']==$microVoteCensus[$key-1]['num'])
			{   
				$microVoteCensus[$key]['sort']=$microVoteCensus[$key-1]['sort'];
			}else{
				$i++;
				$v['sort']=$i;
			}
			
			
		}
		
		$this->microVoteCensus=$microVoteCensus;
		$this->display();
	}
}